// app.js

// 1. 全局引入并执行util.js
import './utils/utils'
// 2. 全局引入并执行http.js
import './utils/http'
// 3. 全局引入并执行verify.js
import './utils/verify'

App({
  onLaunch() {
    this.getToken('token')
    this.getToken('refreshToken')
  },
  // ------------自定义的各类方法
  // 1. 获取token
  getToken(key) {
    wx.getStorage({
      key,
      success: (res) => {
        // 把token存储到全局
        this[key] = res.data
      },
    })
  },

  // 2. 存token和refreshToken
  setToken(token, refreshToken) {
    token = `Bearer ${token}`
    refreshToken = `Bearer ${refreshToken}`

    this.token = token
    this.refreshToken = refreshToken

    wx.setStorageSync('token', token)
    wx.setStorageSync('refreshToken', refreshToken)
  },
})
